package com.mrtan.controller;
import cn.dev33.satoken.util.SaResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mrtan.bean.Result;
import com.mrtan.service.OrderService;
import com.mrtan.vo.OrderInsertVO;
import com.mrtan.vo.OrderWhereVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 销售业务和采购业务
 *
 */

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    //显示仓库和库存
    @GetMapping("/show")
    public SaResult show(OrderWhereVO orderWhereVO,
                         @RequestParam(defaultValue = "1") int page,
                         @RequestParam(defaultValue = "10") int limit){
        PageHelper.startPage(page,limit); // 在查询之前使用,会自动对紧接着的第一个查询进行分页
        List<Result> list= orderService.findAll(orderWhereVO);
        PageInfo<Result> pageInfo = new PageInfo<>(list);
        System.out.println(pageInfo.getList());
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","success");
        map.put("data",pageInfo.getList());
        map.put("count",pageInfo.getTotal());
        return SaResult.ok()
                .setData(pageInfo.getList())
                .set("count",pageInfo.getTotal());
    }

    //生成订单
    @PutMapping("/sell")
    public SaResult addsell(OrderInsertVO orderInsertVO){
        orderService.addSell(orderInsertVO);
        return SaResult.ok();
    }
    //生成订单详情

}
